<template>
    <div>
        <el-card>
          <h2>测试---首页</h2>
          欢迎：<span v-text="username" style="width: 150px">&nbsp,&nbsp,&nbsp</span>
        </el-card>

      <el-card style="margin-top: 50px">
        <h3>基础操作</h3>
        <el-row>

          <el-button type="primary" @click="Perfect">完善资料获得成长值</el-button>
          <el-button type="success" @click="changVip">成为会员获取会员积分</el-button>
          <el-button  @click="share">分享获得成长值</el-button>
          <el-button type="warning"  @click="invite">邀请新用户获得成长值</el-button>
          <el-button type="danger" @click="userLog">每日签到获得成长值</el-button>
        </el-row>

      </el-card>

      <el-card style="margin-top: 50px">
        <el-button type="primary" @click="goNextPage">去下一个页面</el-button>
        <el-button type="danger" @click="loginOut">退出登录</el-button>



      </el-card>

<!--      完善资料-->
      <div>
        <el-dialog title="完善资料" ref="editEmpRefForm" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
          <el-form :model="userForm" size="small" ref="editEmpRefForm" >
            <el-form-item label="性别" :label-width="formLabelWidth" prop="gender">
              <el-input v-model="userForm.gender" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="年龄" :label-width="formLabelWidth" prop="age">
              <el-input v-model="userForm.age" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="微信" :label-width="formLabelWidth" prop="vx">
              <el-input v-model="userForm.vx" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="职业" :label-width="formLabelWidth" prop="occupation">
              <el-input v-model="userForm.occupation" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="常用收货人" :label-width="formLabelWidth" prop="consignee">
              <el-input v-model="userForm.consignee" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="地址" :label-width="formLabelWidth" prop="address">
              <el-input v-model="userForm.address" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="来源方式" :label-width="formLabelWidth" prop="source">
              <el-input v-model="userForm.source" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>

          <div slot="footer" class="dialog-footer">
            <el-button @click.prevent="cancelCourseEdit">取 消</el-button>
            <el-button type="primary" @click.prevent="saveUser">确 定</el-button>
          </div>
        </el-dialog>
      </div>
<!--      成为尊贵的vip-->
      <div>
        <el-dialog title="会员等级" ref="editEmpRefForm" :visible.sync="dialogFormVisible2" :close-on-click-modal="false">
          <el-table
              :data="vipList"
              style="width: 100%;margin-bottom: 20px;"
              row-key="id"
              border
              default-expand-all
              :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
            <el-table-column
                prop="name"
                label="会员等级"
                width="180">
            </el-table-column>
            <el-table-column
                prop="duration"
                label="有效时长"
                width="180">
            </el-table-column>
            <el-table-column
                prop="finalprice"
                label="会员价格"
                width="180">
            </el-table-column>

            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                    size="mini"
                    type="warning"
                    @click="buy(scope.row)">购买</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-button type="primary" @click="cancelCourseEdit2">取 消</el-button>
        </el-dialog>
      </div>


    </div>
</template>

<script>
    export default {
      name: "WelCome",

      data() {
        return {
          isSvip:0,
          username:'',
          addValueForm:{
            uid:0,
            username:'',
            growthValue:0,
            beiZhu:''
          },
          worthForm:{
            perfectGet:0,
            shareGet:0,
            inviteGet:0,
            signGet:0,
          },
          user: {},
          userForm: {
            id:'',
            userId:'',
            growthValue:'',
            gender:'',
            age:'',
            vx:'',
            occupation:'',
            consignee:'',
            address:'',
            source:'',
          },
          userId:0,
          pageNum: 1,
          pageSize: 5,
          vipid: 0,
          integral:0,
          imageUrl5: '',//组件选中图片反显需要
          vipList:[],
          url5: this.$MyUrl.serverUrl + 'emp/upload5',//上传地址
          dialogFormVisible:false,
          dialogFormVisible2:false,
          formLabelWidth:'120px',
          userInfoTest:{
            username:'哼哈哈哈哈',
            password:''
          },
        }
      },

      methods:{
        //下一页
        goNextPage(){
          this.$router.push("/Page2")
        },
        //邀请新用户涨成长值
        share(){
          this.$confirm('复制链接发送给好友', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {

            this.addValueForm.uid = this.userId
            this.addValueForm.username = this.username
            this.addValueForm.growthValue = this.worthForm.inviteGet
            this.addValueForm.beiZhu = '复制链接邀请'
            let url = "course/addLogValue";
            this.$axios.post(url, this.addValueForm).then(res => {
              if (res.data.code == 200) {
                console.log(res)
                this.vipList = res.data.data.list;
                this.pageNum = res.data.data.pageNum;
                this.pageSize = res.data.data.pageSize;
                this.total = res.data.data.total;
              } else {
                this.$message({
                  type: "error",
                  message: res.data.msg,
                  duration: 1000
                })
              }
            })

          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消分享'
            });
          });



        },
        //分享涨成长值
        invite() {
          this.$confirm('是否分享该产品?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
                this.addValueForm.uid = this.userId
                this.addValueForm.username = this.username
                this.addValueForm.growthValue = this.worthForm.shareGet
                this.addValueForm.beiZhu = '分享'
                let url = "course/addLogValue";
                this.$axios.post(url, this.addValueForm).then(res => {
                  if (res.data.code == 200) {
                    console.log(res)
                    this.vipList = res.data.data.list;
                    this.pageNum = res.data.data.pageNum;
                    this.pageSize = res.data.data.pageSize;
                    this.total = res.data.data.total;
                  } else {
                    this.$message({
                      type: "error",
                      message: res.data.msg,
                      duration: 1000
                    })
                  }
                })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消分享'
            });
          });
        },
        //签到涨成长值
        userLog() {
          this.$confirm('是否进行每日签到?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.addValueForm.uid = this.userId
            this.addValueForm.username = this.username
            this.addValueForm.growthValue = this.worthForm.signGet
            this.addValueForm.beiZhu = '签到'
            let url = "course/addLogValue";
            this.$axios.post(url, this.addValueForm).then(res => {
              if (res.data.code == 200) {
                console.log(res)
                this.vipList = res.data.data.list;
                this.pageNum = res.data.data.pageNum;
                this.pageSize = res.data.data.pageSize;
                this.total = res.data.data.total;
              } else {
                this.$message({
                  type: "error",
                  message: res.data.msg,
                  duration: 1000
                })
              }

            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消签到'
              });
            })
          })
        },
        //成为会员
        buy(row){
          console.log("qwert")
          console.log(row.id)
          console.log(this.userId)
          console.log(row.finalprice)
          console.log(this.isSvip)
          console.log(this.username)
          console.log("qwert")
          let url = "course/addVip";
          this.$axios.get(url, {
            params: {
              vipid:row.id,
              userId:this.userId,
              integral:row.finalprice,
              isSvip:this.isSvip,
              username:this.username

            }
          }).then(res => {
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: res.data.msg,
                duration: 1000
              })
              this.dialogFormVisible2 = false ;
              this.get

            } else {
              this.$message({
                type: "error",
                message: res.data.msg,
                duration: 1000
              })
            }
          })

        },
        //查询会员等级
        getVipList(){
          let url = "svip/queryByPage";
          this.$axios.get(url,{
            params:{
              now:this.pageNum,
              size:this.pageSize
            }
          }).then(res=>{
            if (res.data.code == 101){
              console.log(res)
              this.vipList = res.data.data.list;
              this.pageNum = res.data.data.pageNum;
              this.pageSize = res.data.data.pageSize;
              this.total = res.data.data.total;
            }else {
              this.$message({
                type:"error",
                message:res.data.msg,
                duration:1000
              })
            }
          });
        },
        //保存 完善的个人信息
        saveUser() {
          this.$refs.editEmpRefForm.validate(valid => {
            if (!valid) {
              return;
            }
            let url = "course/modityUser"
            this.$axios.put(url, this.userForm).then(res => {
              if (res.data.code = 200) {
                this.$message({
                  type: "success",
                  message: res.data.msg,
                  duration: 1000
                })
                //增加成长值
                this.addsaveUserValue();
                this.dialogFormVisible = false ;

              } else {
                this.$message({
                  type: "error",
                  message: res.data.msg,
                  duration: 1000
                })
              }
            })
          })
        },
        //增加成长值 完善资料
        addsaveUserValue(){
          this.addValueForm.uid=this.userId
          this.addValueForm.username=this.username
          this.addValueForm.growthValue=this.worthForm.perfectGet
          this.addValueForm.beiZhu='完善资料'
          let url = "course/addLogValue";
          this.$axios.post(url,this.addValueForm).then(res=>{
            if (res.data.code == 200){
              console.log(res)
              this.vipList = res.data.data.list;
              this.pageNum = res.data.data.pageNum;
              this.pageSize = res.data.data.pageSize;
              this.total = res.data.data.total;
            }else {
              this.$message({
                type:"error",
                message:res.data.msg,
                duration:1000
              })
            }
          });
        },
        //取消成为会员模态框
        cancelCourseEdit2(){
          this.dialogFormVisible2 = false ;
          // alert("111")
          this.$message({
            type:"error",
            message:"真的就不再考虑了嘛~",
            duration:1000
          });
          // //清空修改表单里面的内容
          // this.$refs.editEmpRefForm.resetFields();
        },
        //取消修改个人信息
        cancelCourseEdit(){
          this.dialogFormVisible = false ;
          // alert("111")
          this.$message({
            type:"error",
            message:"已取消完善信息",
            duration:1000
          });
          //清空修改表单里面的内容
          this.$refs.editEmpRefForm.resetFields();
        },
        //成为会员
        changVip(){
          this.dialogFormVisible2 = true ;
        },
        //完善 资料
        Perfect(){
          this.dialogFormVisible = true ;
          this.getEmpByAccount();
        },
        //根据名字查列表
        getEmpByAccount() {
          // let userjs =sessionStorage.getItem('userInfo');
          // let user=JSON.parse(userjs);

          let url = "tuser/queryUserDetails";
          this.$axios.get(url,{
            params:{
              uid:this.userId,
            }
          }).then(res=>{
            if (res.data.code == 200){
              this.$message({
                type:"success",
                message:res.data.msg,
                duration:1000
              });
              this.userForm= res.data.data[0];
              console.log("*********")
              console.log(res.data.data)
              console.log("*********")
            }else {
              this.$message({
                type:"error",
                message:res.data.msg,
                duration:1000
              })
            }
          });

        },
        //获得相对的成长值
        getGrowth(){
          let url = "course/getGrowth";
          this.$axios.get(url).then(res => {
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: res.data.msg,
                duration: 1000
              })
              this.worthForm=res.data.data;


            } else {
              this.$message({
                type: "error",
                message: res.data.msg,
                duration: 1000
              })
            }
          });
        },

        //退出登录
        loginOut(){
          // sessionStorage.clear();
          // this.$router.push("/Page0");
        },
        //解析localStorage 中用户信息
        initEmpTest(){
          let jsonStr = sessionStorage.getItem("user");
          console.log(jsonStr)
          if (jsonStr){
            this.user = JSON.parse(jsonStr);
            this.userId=this.user.id;
            this.username=this.user.username;
            this.isSvip=this.user.isSvip;
          }
        },



      },
      created() {
        this.initEmpTest()
        this.getVipList();
        this.getEmpByAccount();
        this.getGrowth();
        console.log("*********************")
        console.log(this.vipList)
        console.log("*********************")
      }
    }
</script>

<style scoped>


</style>